﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SachOnlineLibrary.Public;
using System.Data;
using System.Data.SqlClient;
using System.Data;
using SachOnlineLibrary.Public;
namespace SachOnlineLibrary.DAL
{
    public class ChuDeDAL
    {
        KetNoiDB ketnoi = new KetNoiDB();
        internal DataTable LietKeTatCaChuDe()
        {
            DataTable dt = new DataTable();
            dt = null;
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "Select * from loai";
            try
            {
                dt = ketnoi.ExecuteQuery(cmd);
            }
            catch (Exception ex)
            {
            }
            return dt;
        }
        public bool SuaTheLoai(int maloai, string tenloai)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "update loai set tenloai = @tenloai where maloai = @maloai";
            cmd.Parameters.Add("@maloai", SqlDbType.Int).Value = maloai;
            cmd.Parameters.Add("@tenloai", SqlDbType.NVarChar).Value = tenloai;
            return ketnoi.ExecuteNonQuery(cmd);
        }
        public bool ThemTheLoai(string tenloai)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "insert into loai values(@tenloai)";
            cmd.Parameters.Add("@tenloai", SqlDbType.NVarChar).Value = tenloai;
            return ketnoi.ExecuteNonQuery(cmd);
        }
        public bool XoaTheLoai(int maloai)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "delete loai where maloai = @maloai";
            cmd.Parameters.Add("@maloai", SqlDbType.Int).Value = maloai;
            return ketnoi.ExecuteNonQuery(cmd);
        }
    }
}
